<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
    <title></title>
    <meta name="keywords" content="智辉CRM">
    <meta name="description" content="智辉CRM">
    <link rel="Bookmark" href="favicon.ico">
    <link rel="Shortcut Icon" href="favicon.ico" />
    <!--[if lt IE 9]> 
    <script type="text/javascript" src="Lib/html5.js"></script>
    <script type="text/javascript" src="Lib/respond.min.js"></script>
    <script type="text/javascript" src="Lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="__PUBLIC__/css/H-ui.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
    <link href="__PUBLIC__/css/style.css" rel="stylesheet" type="text/css" />
    <link href="Tpl/Service/common/order/page01.css" rel="stylesheet" type="text/css" />
    <!--自己的样式-->
   <!--  <link href="Tpl/Assistant/common/expense/expense_add.css" rel="stylesheet" type="text/css"> -->
    <!--[if IE 6]> 
    <script type="text/javascript" src="Lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('.pngfix,.icon');</script> 
    <![endif]-->
    
</head>

<body>
    <assign name="getType" value="$Think.get.type"/>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 企业号管理 <span class="c-gray en">&gt;</span> 人员在线 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>

<div class="pd-20">
    <form action="" method="get">
    <input type="hidden" name="m" value="Admin"/>
    <input type="hidden" name="c" value="WechatEnt"/>
    <input type="hidden" name="a" value="onlineState"/>

    <div class="cl pd-5 bg-1 bk-gray mt-20">
    <div class="text-l">
            <select name="community_id" id="community_id" class="select" style="width: 15%;height: 30px">
                <volist name="dep" id="v">
                    <option value="{$v.id}">{$v.name}</option>
                </volist>
            </select>
    </div>
    </div>
    </form>
    <div class="mt-20">
    <table class="table table-border table-bordered table-hover table-bg table-sort">
        <thead>
            <tr role="row"><th rowspan="1" scope="col" colspan="11">{$title}</th></tr>
            <tr class="text-c">
                <th>姓名</th>
                <th>小区</th>
                <th>岗位</th>
                <th>当前状态</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            
                <tr id="roll"></tr>
                <tr class="text-c">
                    
                </tr>
            
        </tbody>
    </table>
    <div style="width: 100%;margin: 10px 0">{$page}</div>  
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script> 
<!-- <script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>  -->
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.js"></script> 
<script type="text/javascript" src="__PUBLIC__/js/H-ui.admin.js"></script>  
<!-- <script type="text/javascript" src="Tpl/Admin/common/wechat/lunxun.js"></script>  -->
<script type="text/javascript">
        getTable();

        function to(url){
            layer.open({
                type: 2,
                title: '修改',
                maxmin: true,
                fix:false,
                area: ['820px', '500px'],
                content: url
            });

        };

        $("#community_id").change(function(){
            getTable();
        });

        function getTable(){
            var depId = $("#community_id").val();
            $("tbody tr").empty();
            $.ajax({
                type:"get",
                url:'/index.php?m=Admin&c=WechatEnt&a=getCommunityEmployee&id='+depId,
                success:function(data){
                    console.log(data);
                    if(data.status == false){

                    }else{
                        // console.log(data);
                        for (var i = 0; i < data.employee.length; i++) {
                            var remark = data.employee[i].remark?data.employee[i].remark:'';
                        var str = "<tr  class='text-c'>";
                        str += "<td>"+data.employee[i].name+"</td>";
                        str += "<td>"+data.employee[i].department_name+"</td>";
                        str += "<td>"+data.employee[i].position_title+"</td>";
                        str += "<td class='td-status'>"+statusState(data.employee[i].onLine)+"</td>";
                        str += "<td>"+remark+"</td>";
                        if(data.employee[i].onLine==1){
                            str += "<td class='f-14 td-manage'><a style='text-decoration:none' onClick='admin_stop(this,&#39;"+data.employee[i].id+"&#39;,&#39;-1&#39;,&#39;1&#39;)' href='javascript:;' title='离线' uid='"+data.employee[i].id+"'><i class='Hui-iconfont'>&#xe631;</i></a></td></tr>";
                        }else{
                            str += "<td class='f-14 td-manage'><a style='text-decoration:none' onClick='admin_start(this,&#39;"+data.employee[i].id+"&#39;,&#39;1&#39;,&#39;1&#39;)' href='javascript:;' title='在线' uid='"+data.employee[i].id+"'><i class='Hui-iconfont'>&#xe615;</i></a></td></tr>";
                        }
                        

                        $("#roll").after(str);
                        }


                        for (var i = 0; i < data.assistant.length; i++) {
                            var str = "<tr class='text-c'>";
                            str += "<td>"+data.assistant[i].real_name+"</td>";
                            str += "<td>"+data.assistant[i].DEPT_NAME+"</td>";
                            str += "<td>前台客服</td>";
                            str += "<td class='td-status'>"+statusState(data.assistant[i].onLine)+"</td>";
                            str += "<td></td>";
                            if(data.assistant[i].onLine== 1){
                            str += "<td class='f-14 td-manage'><a style='text-decoration:none' onClick='admin_stop(this,&#39;"+data.assistant[i].id+"&#39;,&#39;-1&#39;,&#39;2&#39;)' href='javascript:;' title='离线' uid='"+data.assistant[i].id+"'><i class='Hui-iconfont'>&#xe631;</i></a></td></tr>";
                            }else{
                                str += "<td class='f-14 td-manage'><a style='text-decoration:none' onClick='admin_start(this,&#39;"+data.assistant[i].id+"&#39;,&#39;1&#39;,&#39;2&#39;)' href='javascript:;' title='在线' uid='"+data.assistant[i].id+"'><i class='Hui-iconfont'>&#xe615;</i></a></td></tr>";
                            }

                            $("#roll").after(str);
                        }
                }
                    
            }
        })
    }

    function statusState(status){
        if(status==1)
            return "<span class='label label-success radius'>在线</span>";
        else
            return "<span class='label radius'>离线</span>";
    }

    /*管理员-停用*/
function admin_stop(obj,id,status,type){
    layer.confirm('确认要离线吗？',function(index){
        
        //此处请求后台程序，下方是成功后的前台处理……
        dataAdmin(obj,id,status,type);
        
    });
}

/*管理员-启用*/
function admin_start(obj,id,status,type){
    layer.confirm('确认要在线吗？',function(index){
        //此处请求后台程序，下方是成功后的前台处理……
        
    dataAdmin(obj,id,status,type);
        
    });
}


// 管理员停用启用ajax
function dataAdmin(obj,id,status,type){
    if(type==1)
    var ajaxUrl = '/index.php?m=Admin&c=WechatEnt&a=employeeState';
    if(type==2)
    var ajaxUrl = '/index.php?m=Admin&c=WechatEnt&a=assistantState';

    $.ajax({
        url:ajaxUrl,
        type:"POST",
        data:{
            status:status,
            id:id
        },
        error:function(){
            console.log("服务器繁忙");
        },
        success:function(data){
            if(data.status==1){
                if(status==1){
                    $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,'+id+',-1,'+type+')" href="javascript:;" title="离线" uid="'+id+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">在线</span>');
                    $(obj).remove();
                    layer.msg('成功在线!',{icon: 6,time:1000});


                    
                }else{
                    $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,'+id+',1,'+type+')" href="javascript:;" title="在线" uid="'+id+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label  radius">离线</span>');
                    $(obj).remove();
                    layer.msg('成功离线!', {icon: 5,time:1000});
                }
            }else
            layer.msg('修改失败!', {icon: 5,time:1000});
        }
    });
}

</script> 

</body>

</html>

